/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package haw.pr2.A2a.implementations;
import haw.pr2.A2a.interfaces.*;
import static haw.pr2.A2a.implementations.UtilityclassValues.*;
/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class LengthInM extends AbstractScalar<Length> implements Length , Comparable<Length> {

    private final double lengthInM;

    LengthInM(double lengthInM) {
        this.lengthInM=lengthInM;
    }
    
    @Override
    public Length inverse() {
        return new LengthInM(-this.m());
    }

    @Override
    public Length add(Length value) {
        return new LengthInM(this.m()+value.m());
    }

    @Override
    public Length sub(Length value) {
        return new LengthInM(this.m()-value.m());
    }

    @Override
    public Length mul(double value) {
        return new LengthInM(this.m()*value);
    }

    @Override
    public Length div(double value) {
        return new LengthInM(this.m()/value);
    }

    @Override
    public double div(Length value) {
        return this.m()/value.m();
    }

    @Override
    public boolean isZero() {
        return this.equals(ZERO_LENGTH);
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public double ft() {
        return this.m()*UtilityclassValues.M_IN_FT;
    }

    @Override
    public double m() {
        return this.lengthInM;
    }

    @Override
    public double km() {
        return this.m()*M_IN_KM;
    }

    @Override
    public double nm() {
        return this.m()*UtilityclassValues.M_IN_NM;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof Length)) return false;
        return this.compareTo((Length)obj) == 0;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 61 * hash + (int) (Double.doubleToLongBits(this.lengthInM) ^ (Double.doubleToLongBits(this.lengthInM) >>> 32));
        return hash;
    }
    
    @Override
    public int compareTo(Length l) {
       return Double.compare(this.m(),l.m());
    }

    @Override
    public double toDouble() {
        return this.m();
    }

    public static Length valueOf(double value) {
        return new LengthInM(value);
    }
}